﻿using System;
using System.IO;

namespace ExcelConfig.Template
{
    public class ExcelTemplateStreamFile : IDisposable
    {
        internal Stream stream;
        public ExcelTemplateStreamFile(Stream stream)
        {
            this.stream = stream;
        }

        public void Dispose()
        {
            if (this.stream != null)
            {
                this.stream.Dispose();
                this.stream = null;
            }
        }

        /// <summary>
        /// 填充数据，并输出
        /// </summary>
        /// <param name="path"></param>
        /// <param name="obj"></param>
        public void TemplateOut(object obj, Stream output)
        {
            MiniExcel.SaveAsByTemplate(output, stream, obj);
            output.Position = 0;
        }
    }
}
